
#import "DownloadTorrentListViewCell.h"

@implementation DownloadTorrentListViewCell

//
// name
//
@synthesize nameLabel														= _nameLabel;

//
// status
//
@synthesize statusLabel														= _statusLabel;

//
// done/size
//
@synthesize doneSizeLabel													= _doneSizeLabel;

//
// done percent
//
@synthesize donePercentLabel												= _donePercentLabel;

//
// upload rate
//
@synthesize uploadRateLabel													= _uploadRateLabel;

//
// download rate
//
@synthesize downloadRateLabel												= _downloadRateLabel;

//
// share ratio
//
@synthesize shareRatioLabel													= _shareRatioLabel;

//
// init
//
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{
	//
	// call super
	//
	self																	= [super initWithStyle:style reuseIdentifier:reuseIdentifier];
	if(!self)
		return nil;
	
	//
	// create name label
	//
	self.nameLabel															= [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
	self.nameLabel.textAlignment											= UITextAlignmentLeft;
	self.nameLabel.lineBreakMode											= UILineBreakModeTailTruncation;
	self.nameLabel.font														= [UIFont boldSystemFontOfSize:17];
	self.nameLabel.backgroundColor											= [UIColor clearColor];
	[self.contentView addSubview:self.nameLabel];
	
	//
	// create status label
	//
	self.statusLabel														= [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
	self.statusLabel.textAlignment											= UITextAlignmentLeft;
	self.statusLabel.textColor												= [UIColor colorWithRed:168 / 255.f green:110 / 255.f blue:43 / 255.f alpha:1];
	self.statusLabel.lineBreakMode											= UILineBreakModeTailTruncation;
	self.statusLabel.font													= [UIFont systemFontOfSize:14];
	self.statusLabel.backgroundColor										= [UIColor clearColor];
	[self.contentView addSubview:self.statusLabel];
	
	//
	// create done/size label
	//
	self.doneSizeLabel														= [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
	self.doneSizeLabel.textAlignment										= UITextAlignmentLeft;
	self.doneSizeLabel.textColor											= [UIColor grayColor];
	self.doneSizeLabel.lineBreakMode										= UILineBreakModeTailTruncation;
	self.doneSizeLabel.font													= [UIFont systemFontOfSize:14];
	self.doneSizeLabel.backgroundColor										= [UIColor clearColor];
	[self.contentView addSubview:self.doneSizeLabel];
	
	//
	// create done percent label
	//
	self.donePercentLabel													= [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
	self.donePercentLabel.textAlignment										= UITextAlignmentRight;
	self.donePercentLabel.textColor											= [UIColor grayColor];
	self.donePercentLabel.lineBreakMode										= UILineBreakModeTailTruncation;
	self.donePercentLabel.font												= [UIFont systemFontOfSize:14];
	self.donePercentLabel.backgroundColor									= [UIColor clearColor];
	[self.contentView addSubview:self.donePercentLabel];
	
	//
	// create upload rate label
	//
	self.uploadRateLabel													= [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
	self.uploadRateLabel.textAlignment										= UITextAlignmentLeft;
	self.uploadRateLabel.textColor											= [UIColor grayColor];
	self.uploadRateLabel.lineBreakMode										= UILineBreakModeTailTruncation;
	self.uploadRateLabel.font												= [UIFont systemFontOfSize:14];
	self.uploadRateLabel.backgroundColor									= [UIColor clearColor];
	[self.contentView addSubview:self.uploadRateLabel];
	
	//
	// create download rate label
	//
	self.downloadRateLabel													= [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
	self.downloadRateLabel.textAlignment									= UITextAlignmentRight;
	self.downloadRateLabel.textColor										= [UIColor grayColor];
	self.downloadRateLabel.lineBreakMode									= UILineBreakModeTailTruncation;
	self.downloadRateLabel.font												= [UIFont systemFontOfSize:14];
	self.downloadRateLabel.backgroundColor									= [UIColor clearColor];
	[self.contentView addSubview:self.downloadRateLabel];
	
	//
	// create share ratio label
	//
	self.shareRatioLabel													= [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
	self.shareRatioLabel.textAlignment										= UITextAlignmentRight;
	self.shareRatioLabel.textColor											= [UIColor grayColor];
	self.shareRatioLabel.lineBreakMode										= UILineBreakModeTailTruncation;
	self.shareRatioLabel.font												= [UIFont systemFontOfSize:14];
	self.shareRatioLabel.backgroundColor									= [UIColor clearColor];
	[self.contentView addSubview:self.shareRatioLabel];
	
	return self;
}

//
// dealloc
//
- (void)dealloc
{
	self.nameLabel															= nil;
	self.statusLabel														= nil;
	self.doneSizeLabel														= nil;
	self.donePercentLabel													= nil;
	self.uploadRateLabel													= nil;
	self.downloadRateLabel													= nil;
	self.shareRatioLabel													= nil;
	
	[super dealloc];
}

//
// layout subviews
//
- (void)layoutSubviews
{
	[super layoutSubviews];
	
	CGRect bounds															= self.contentView.bounds;
	
	CGFloat x																= 10;
	CGRect nameFrame														= CGRectMake(x, 2, bounds.size.width - x - 2, 20);
	self.nameLabel.frame													= nameFrame;
	
	CGRect statusFrame														= CGRectMake(x, nameFrame.origin.y + nameFrame.size.height, 70, 18);
	self.statusLabel.frame													= statusFrame;
	CGRect shareRatioFrame													= CGRectMake(statusFrame.origin.x + statusFrame.size.width, statusFrame.origin.y, nameFrame.size.width - statusFrame.size.width, 18);
	self.shareRatioLabel.frame												= shareRatioFrame;
	
	CGRect doneSizeFrame													= CGRectMake(x, statusFrame.origin.y + statusFrame.size.height, nameFrame.size.width - 120, 18);
	self.doneSizeLabel.frame												= doneSizeFrame;
	CGRect donePercentFrame													= CGRectMake(doneSizeFrame.origin.x + doneSizeFrame.size.width, doneSizeFrame.origin.y, nameFrame.size.width - doneSizeFrame.size.width, 18);
	self.donePercentLabel.frame												= donePercentFrame;
	
	CGRect uploadRateFrame													= CGRectMake(x, doneSizeFrame.origin.y + doneSizeFrame.size.height, nameFrame.size.width / 2, 18);
	self.uploadRateLabel.frame												= uploadRateFrame;
	CGRect downloadRateFrame												= CGRectMake(uploadRateFrame.origin.x + uploadRateFrame.size.width, uploadRateFrame.origin.y, nameFrame.size.width - uploadRateFrame.size.width, 18);
	self.downloadRateLabel.frame											= downloadRateFrame;
}

//
// row height
//
+ (CGFloat)rowHeight
{
	return 78;
}
@end

